package leetcode_1301_1400;

import java.util.HashSet;
import java.util.Set;

public class LeeCode_1376 {
    public static void main(String[] args) {
        System.out.println(numOfMinutes(1, 0, new int[]{-1}, new int[]{0}));
    }
    private static int numOfMinutes(int n, int headID, int[] manager, int[] informTime) {
        int ans = Integer.MIN_VALUE;
        if (n == 1){
            return informTime[0];
        }
        for (int i = 0; i < manager.length; i++) {
            if (informTime[i] != 0)
                continue;
            int index = i;
            int time = informTime[headID];
            while (manager[index] != -1){
                time += informTime[index];
                index = manager[index];
            }
            ans = Math.max(ans, time);
        }
        return ans;
    }
}
